package org.wattdepot.cli.processor;

import java.util.List;
import org.wattdepot.cli.command.WattCarbonContent;

/**
 * Implements the Chart command for the WattDepotCLI.
 * 
 * @author Kimberly Heu, Kendyll Doi
 * 
 */
public class CarbonContentCommand extends CommandLineInterface implements WattDepotCliCommand {
  /**
   * Parses the Chart command.
   * 
   * @param args The arguments of the user's command.
   * @return The string from executing the command.
   */
  public String doCommand(List<String> args) {
    String output = ""; // output string
    StringBuffer buf = new StringBuffer(500); // buffer for output information
    int interval = 0;

    if (args.size() == 5) {
      if (args.get(3).equalsIgnoreCase("sampling-interval")) {
        try {
          interval = Integer.parseInt(args.get(4));
        }
        catch (Exception e) {
          System.out.println("Error converting to integer");
          return "Interval needs to be a number";
        }
        buf.append(WattCarbonContent.wattCarbonContent(args.get(1), args.get(2), interval, client));
      }
      else {
        buf.append("Invalid input to carboncontent command. Use help for more information.");
      }
    }
    else {
      buf.append("Invalid input to carboncontent command. Use help command for more information");
    }

    output = buf.toString();
    return output;
  }
}
